package a.codetop;

public class _8子串_最大和 {

    public static void main(String[] args) {
        int[] nums = {-2,1,-3,4,-1,2,1,-5,4}; int[] dp = new int[nums.length]; int n = nums.length;

        dp[0] = nums[0];
        for (int i = 1; i < n ; i++) {
            //要么自个,要么前面的max
            dp[i] = Math.max(nums[i],nums[i]+dp[i-1]);
        }

        //再遍历
        int max = nums[0];
        for (int i = 0; i < dp.length; i++)max =Math.max(dp[i],max);
        System.out.println(max);
    }
}
